(define *kR:utils:toggle-states* (list))
(define *kR:utils:toggle-state-counter* (list))

(define (toggle:reset)
   (set! *kR:utils:toggle-states* (list))
   (set! *kR:utils:toggle-state-counter* 0)
)

; calls a function with a toggling state and given args 
(define (toggle id start fn . args) 
   (let ((val (get-obj-for-key-with-default id *kR:utils:toggle-states* start)))
          (set-obj-for-key! id (not val) *kR:utils:toggle-states*)
          (fn val args)
          val
))


; Increments a globarl variable and returns the result
(define-macro (inc! var)
   (set! ,var (+ ,var 1)
   ,var))

(define (kR:utils:inc-toggle-counter)
   (inc! *kR:utils:toggle-states*))

